#include <iostream>
using namespace std;
#define ERROR -1
#define OK -2
typedef struct Lnode
{
    int date;
    struct Lnode* next;
} LNode, * LinkList;

void Print_R(LinkList L)
{
    LinkList p;
    p = L;
    p = p->next;
    while (p) {
        cout << p->date << endl;
        p = p->next;
    }
    cout << L->date << endl;
}

int Find_R(LinkList L, int i, int n)
{
    if (i > n || i <= 0) {
        return ERROR;
    }
    int j = 1;
    LinkList p;
    p = L;
    p = p->next;
    while (p) {
        if (j == i) {
            return p->date;
        }
        p = p->next; // 循环到最后p就为"NULL"
        ++j;
    }
    if (p) {
        return ERROR;
    }
}

int Add_R(LinkList L, int i, int n)
{
    if (i > n || i <= 0) {
        return ERROR;
    }
    int j = 1;
    LinkList p;
    p = L;
    p = p->next;
    while (p) {
        if (j == i - 1) {
            LinkList s;
            s = new LNode;
            cin >> s->date;
            s->next = p->next;
            p->next = s;
            ++L->date;
            return OK;
        }
        p = p->next;
        ++j;
    }
    if (p) {
        return OK;
    }
}

int Delete_R(LinkList L, int i, int n)
{
    if (i > n || i <= 0) {
        return ERROR;
    }
    LinkList p;
    p = L;
    p = p->next;
    int j = 1;
    while (p) {
        if (j == i - 1) {
            LinkList Del;
            Del = p->next;
            p->next = Del->next;
            --L->date;
            return OK;
        }
        p = p->next;
        ++j;
    }
}

void Sum_R(LinkList L, int n)
{
    int j = 0;
    LinkList p;
    p = L;
    p = p->next;
    while (p) {
        ++j;
        p = p->next;
    }
    cout << j << endl;
}

void CreateList_R(LinkList& L, int n)
{
    L = new LNode;
    L->date = 0;
    L->next = NULL;
    LinkList  r;
    r = L;
    for (int i = 0; i < n; i++) {
        LinkList p;
        p = new LNode;
        cin >> p->date;
        p->next = NULL;
        r->next = p;
        r = p;
        ++L->date;
    }
}


int main() {
    int FindNum, AddNum, DelNum;
    LinkList L;
    CreateList_R(L, 5);
    //FindNum = Find_R(L, 3, 5);
    AddNum = Add_R(L, 3, 5);
    //DelNum = Delete_R(L, 3, 5);
    Print_R(L);
    //cout << DelNum << endl;
    //Sum_R(L, 5);
    return 0;
}